import tweepy

TWITTER_CONSUMER_KEY = '7X4E7yhPcAhcQF0AXnGAg'
TWITTER_CONSUMER_SECRET = 'MboktOOCfFk1jtXcEZwQN9GmYno6vjzjAXVwtsINco'

class TwitterClient(object):

    def __init__(self):        

        ACCESS_KEY = "273238375-ZhrtMRCxZr9dsqMrd6mrVELdHufJsdF6hYkYp7X8"
        ACCESS_SECRET = "fVR0DUcOGK4sYjROAvz4fQ1eL55YERezIhxOE8NfQNY"

        auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
        auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
        self.api = tweepy.API(auth)
        
    def authenticate(self):
        auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
        auth_url = auth.get_authorization_url()
        #verifier = raw_input('PIN: ').strip()
        auth.get_access_token(verifier)        

    def post(self, tweet):
        self.api.update_status(tweet)

    def get_friends_tweets(self):
        return self.api.friends_timeline()

    def get_friends(self, name=''):
        return self._get_filtered(self.api.friends(), 'name', name)

    def get_friend(self, name=''):
        return self.get_friends(name)[0]

    def get_trends(self, name=''):
        return self.api.trends()

    def _get_filtered(self, collection, key, value):
        return [o for o in collection if value in o.__dict__.get(key, '')]

    def get_my_tweets(self):
        return self.api.user_timeline()


if __name__ == '__main__':

    client = TwitterClient()
    print [u.name for u in client.get_friends("Guido")]
    print len([t.text for t in client.get_friends_tweets()])
